package cn.edu.tju.mining.eylmap;

/**
 * @author EYL
 */


import java.io.IOException;
import java.text.ParseException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.edu.tju.mining.Factory;
import cn.edu.tju.mining.vo.report.Report;

@SuppressWarnings("serial")
public class MapServlet extends HttpServlet {

	public MapServlet() {
		super();
	}

	public void destroy() {
		super.destroy(); 
	}
	/**
	 * Parameter rid is the id of the query report.
	 * Url /chart/chart.jsp is the request dispatcher jsp page.
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String rid = request.getParameter("rid");
		Report report = Factory.servReport.getReportById(rid);
		try {
			Drawmap.generatemap(report);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}		
		request.getSession().setAttribute("mapurl", report.getEventSet().getSacleInfo().getTargetUrl());
		RequestDispatcher requestDispatcher=request.getRequestDispatcher("/map/map.jsp");   
		requestDispatcher.forward(request,response);
		//request.getSession().setAttribute("highchartJsScript", report.getDataSet().getHighchartJsString());
		//RequestDispatcher requestDispatcher=request.getRequestDispatcher("/chart/chart.jsp");   
		//requestDispatcher.forward(request,response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

	public void init() throws ServletException {
	}

}
